package com.wbs.controller;


import com.wbs.beans.PageQuery;
import com.wbs.beans.PageResult;
import com.wbs.common.JsonData;
import com.wbs.dao.SysUserMapper;
import com.wbs.model.SysUser;
import com.wbs.param.DeptParam;
import com.wbs.param.UserParam;
import com.wbs.service.SysUserService;
import com.wbs.util.BeanValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sys/user")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    // 新增接口
    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveUser(UserParam user){
        sysUserService.save(user);
        return JsonData.success();
    }

    // 更新部门。注意：中间层的部门发生变化的时候，下边的也都要跟着变化
    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData update(UserParam user){
        sysUserService.update(user);
        return JsonData.success();
    }

    @RequestMapping("/page.json")
    @ResponseBody
    public JsonData page(@RequestParam("deptId") Integer deptId, PageQuery page){
        PageResult<SysUser> result=sysUserService.getPageByDeptId(deptId,page);
        return JsonData.success(result);
    }


}
